package com.zhku.xxl.dao.daoImp;


import com.zhku.xxl.dao.AlumniActivityDao;
import com.zhku.xxl.entity.AlumniActivity;
import jdbc.GenericDao;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class AlumniActivityDaoImp extends GenericDao<AlumniActivity> implements AlumniActivityDao {
    @Override
    public int deleteForName(String name) {
        String sql = "DELETE FROM AlumniActivity"
                + " WHERE name = ?";
        return super.update(sql, name);
    }

    @Override
    public List<AlumniActivity> alumniActivityList(Date data, String name) {
        StringBuilder sqlBuilder = new StringBuilder("SELECT * FROM  AlumniActivity WHERE 1=1");
        List<Object> params = new ArrayList<>();
        if (data != null) {
            sqlBuilder.append(" AND starTime > ? ");
            params.add(data);
        }

        if (name != null && !name.isEmpty()) {
            sqlBuilder.append(" AND name LIKE CONCAT('%', ?, '%')");
            params.add(name);
        }

        String sql = sqlBuilder.toString();
        return super.queryMultiple(sql,super.createRowMapper(AlumniActivity.class), params.toArray());
    }
}
